<template>
  <div class="page-container">
      <van-row>
        <van-col span="20">
          <FortenScan
            ref="scanDom"
            propPlaceholder="请扫描配送单号"
            propErrorMsg="请扫描正确的配送单号"
            :propTypeArr="['wm_dist_key']"
            @scanCall="handleScanOver"
          />
        </van-col>
        <van-col span="4">
          <van-button type="primary" @click="handleGoTo" style="float: right;">
            <van-icon name="plus"/>
          </van-button>
        </van-col>
      </van-row>
      <br>
    <div class="items-container">
      <FortenCollapse   ref="fsList"
                        clickTo="dPick"

                        titleWarningField="skuQtyApply"
                        titleWarningText="申请单品"
                        titleDangerField="billSkuQty"
                        titleDangerText="开单单品"
                        titleSuccessField="pickedSkuQty"
                        titleSuccessText="已拣单品"

                        titleTextField="deptName"
                        titleText="收货科室"
                        groupValueField="deptId"
                        groupTextField="deptName"
                        groupText="收货科室"
                        pkName="id"
                        :keepActive="true"
      >

        <template #default="{item}">
            <van-row>
              <van-col span="24">创建时间:{{item.gmtCreate}}</van-col>
            </van-row>
            <van-row>
              <van-col span="24">拣货时间:{{item.pickDate}}</van-col>
            </van-row>
            <van-row>
              <van-col span="12">拣货人:{{item.picker}}</van-col>
              <van-col span="12">数量:{{item.skuQtyApply}}</van-col>
            </van-row>
            <van-row>
              <van-col span="24">配送类型:{{formatBaseType(item.distType)}}</van-col>
            </van-row>
            <van-row>
              <van-col span="12">配送单号:{{item.busKey}}</van-col>
              <van-col span="12" v-if="item.flowStatus=='start'">流程:制单</van-col>
              <van-col span="12" v-if="item.flowStatus=='submit'">流程:提交</van-col>
              <van-col span="12" v-if="item.flowStatus=='picking'">流程:拣货中 </van-col>
              <van-col span="12" v-if="item.flowStatus=='picked'">流程:拣货完成</van-col>
            </van-row>
            <van-row v-show="item.distType != 'reagent'">
              <van-col span="24">科室地址:{{item.addressName}}</van-col>
            </van-row>
            <van-row v-show="item.distType == 'reagent'">
              <van-col span="24">试剂组名称:{{item.reagentTeamName}}</van-col>
            </van-row>
            <van-row v-show="item.distType == 'reagent'">
              <van-col span="24">试剂组地址:{{item.reagentTeamAddress}}</van-col>
            </van-row>
        </template>
      </FortenCollapse>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { List } from 'vant'
import commonMixin from '@/util/mixin/commonMixin'

Vue.use(List)


export default {
  data() {
    return {
      activeNames: [],
      scan: '',
      distList: [],
    }
  },
  mixins: [commonMixin],
  computed: {
  },
  created() {
    this.getList()
  },
  mounted() {
  },
  components() {
  },
  methods: {
    //扫描
    handleScanOver(scanValue) {
      let hitOb = this.distList.find(ob => ob.busKey == scanValue)
      if (hitOb) {
        this.editDist(hitOb)
        return
      }
      this.scan = scanValue
      this.getList(true)
    },
    //获取所有数据
    getList(isScan) {
      const { pid, toDetail } = this.$route.params
      this.$ajax.get('/wm/dist/listForPDA', {
        params: {
          busKey: this.scan,
          'isScan': isScan && isScan == true
        }
      }).then(resp => {
        if (resp.code == 0 && resp.data) {
          // this.clearForm()
          this.scan = ''
          if (isScan && isScan == true) {
            this.editDist(resp.data[0])
          } else {
            this.distList = resp.data
            this.$refs.fsList.setData(this.distList)
          }
          this.activeNames = resp.data.map(o => o.id)
          if (toDetail) {
            this.$nextTick(() => {
              this.editDist(resp.data.find(d => d.id == pid))
            })
          }

          // this.$notify.success('查询成功')
        }
      })
    },
    getScanType(source) {
      const prefix1 = source.substring(0, 1)
      if (prefix1 == 'D') {
        return 'dist'
      } else if (prefix1 == 'F') {
        return 'rfid'
      } else  {
        return 'sn'
      }
    },
    resetScan() {
      this.scan = ''
      this.$refs.scanDom.focus()
    },
    editDist(dist) {
      //获取点击对象
      this.$router.push({name: 'dPick', params: dist})
    },
    clearForm() {
      this.distList = []
      this.resetScan()
    },
    handleGoTo() {
      this.$router.push({name: 'dpItem'})
    },
    reload() {
      this.getList()
    }
  }
}
</script>
<style scoped>
</style>
